package javolution.xml.sax;

import java.io.IOException;
import javolution.lang.Reusable;
import javolution.text.CharArray;
import javolution.text.Text;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;

/* loaded from: classes2.dex */
public final class SAX2ReaderImpl implements org.xml.sax.XMLReader, Reusable {
    private static Sax2DefaultHandler DEFAULT_HANDLER = new Sax2DefaultHandler();
    private final XMLReaderImpl _parser = new XMLReaderImpl();
    private final Proxy _proxy = new Proxy();

    /* loaded from: classes2.dex */
    private static final class Proxy implements ContentHandler, org.xml.sax.Attributes {
        private Attributes _attributes;
        private org.xml.sax.ContentHandler _sax2Handler = SAX2ReaderImpl.DEFAULT_HANDLER;

        @Override // javolution.xml.sax.ContentHandler
        public void characters(char[] cArr, int i, int i2) throws SAXException {
            this._sax2Handler.characters(cArr, i, i2);
        }

        @Override // javolution.xml.sax.ContentHandler
        public void endDocument() throws SAXException {
            this._sax2Handler.endDocument();
            this._sax2Handler = SAX2ReaderImpl.DEFAULT_HANDLER;
        }

        @Override // javolution.xml.sax.ContentHandler
        public void endElement(CharArray charArray, CharArray charArray2, CharArray charArray3) throws SAXException {
            this._sax2Handler.endElement(charArray.toString(), charArray2.toString(), charArray3.toString());
        }

        @Override // javolution.xml.sax.ContentHandler
        public void endPrefixMapping(CharArray charArray) throws SAXException {
            this._sax2Handler.endPrefixMapping(charArray.toString());
        }

        @Override // org.xml.sax.Attributes
        public int getIndex(String str) {
            Attributes attributes;
            if (str == null || (attributes = this._attributes) == null) {
                return -1;
            }
            return attributes.getIndex(SAX2ReaderImpl.toCharSequence(str));
        }

        @Override // org.xml.sax.Attributes
        public int getIndex(String str, String str2) {
            Attributes attributes;
            if (str == null || str2 == null || (attributes = this._attributes) == null) {
                return -1;
            }
            return attributes.getIndex(SAX2ReaderImpl.toCharSequence(str), SAX2ReaderImpl.toCharSequence(str2));
        }

        @Override // org.xml.sax.Attributes
        public int getLength() {
            Attributes attributes = this._attributes;
            if (attributes != null) {
                return attributes.getLength();
            }
            return 0;
        }

        @Override // org.xml.sax.Attributes
        public String getLocalName(int i) {
            Attributes attributes = this._attributes;
            CharArray localName = attributes != null ? attributes.getLocalName(i) : null;
            return localName != null ? localName.toString() : "";
        }

        @Override // org.xml.sax.Attributes
        public String getQName(int i) {
            Attributes attributes = this._attributes;
            CharArray qName = attributes != null ? attributes.getQName(i) : null;
            return qName != null ? qName.toString() : "";
        }

        @Override // org.xml.sax.Attributes
        public String getType(int i) {
            Attributes attributes = this._attributes;
            if (attributes != null) {
                return attributes.getType(i).toString();
            }
            return null;
        }

        @Override // org.xml.sax.Attributes
        public String getType(String str) {
            Attributes attributes;
            if (str == null || (attributes = this._attributes) == null) {
                return null;
            }
            return attributes.getType(SAX2ReaderImpl.toCharSequence(str)).toString();
        }

        @Override // org.xml.sax.Attributes
        public String getType(String str, String str2) {
            Attributes attributes;
            if (str == null || str2 == null || (attributes = this._attributes) == null) {
                return null;
            }
            return attributes.getType(SAX2ReaderImpl.toCharSequence(str), SAX2ReaderImpl.toCharSequence(str2)).toString();
        }

        @Override // org.xml.sax.Attributes
        public String getURI(int i) {
            Attributes attributes = this._attributes;
            CharArray uri = attributes != null ? attributes.getURI(i) : null;
            return uri != null ? uri.toString() : "";
        }

        @Override // org.xml.sax.Attributes
        public String getValue(int i) {
            Attributes attributes = this._attributes;
            CharArray value = attributes != null ? attributes.getValue(i) : null;
            if (value != null) {
                return value.toString();
            }
            return null;
        }

        @Override // org.xml.sax.Attributes
        public String getValue(String str) {
            Attributes attributes;
            if (str == null || (attributes = this._attributes) == null) {
                return null;
            }
            return attributes.getValue(SAX2ReaderImpl.toCharSequence(str)).toString();
        }

        @Override // org.xml.sax.Attributes
        public String getValue(String str, String str2) {
            Attributes attributes;
            if (str == null || str2 == null || (attributes = this._attributes) == null || attributes.getValue(SAX2ReaderImpl.toCharSequence(str), SAX2ReaderImpl.toCharSequence(str2)) == null) {
                return null;
            }
            return this._attributes.getValue(SAX2ReaderImpl.toCharSequence(str), SAX2ReaderImpl.toCharSequence(str2)).toString();
        }

        @Override // javolution.xml.sax.ContentHandler
        public void ignorableWhitespace(char[] cArr, int i, int i2) throws SAXException {
            this._sax2Handler.ignorableWhitespace(cArr, i, i2);
        }

        @Override // javolution.xml.sax.ContentHandler
        public void processingInstruction(CharArray charArray, CharArray charArray2) throws SAXException {
            this._sax2Handler.processingInstruction(charArray.toString(), charArray2.toString());
        }

        @Override // javolution.xml.sax.ContentHandler
        public void setDocumentLocator(Locator locator) {
            this._sax2Handler.setDocumentLocator(locator);
        }

        @Override // javolution.xml.sax.ContentHandler
        public void skippedEntity(CharArray charArray) throws SAXException {
            this._sax2Handler.skippedEntity(charArray.toString());
        }

        @Override // javolution.xml.sax.ContentHandler
        public void startDocument() throws SAXException {
            this._sax2Handler.startDocument();
        }

        @Override // javolution.xml.sax.ContentHandler
        public void startElement(CharArray charArray, CharArray charArray2, CharArray charArray3, Attributes attributes) throws SAXException {
            this._attributes = attributes;
            this._sax2Handler.startElement(charArray.toString(), charArray2.toString(), charArray3.toString(), this);
        }

        @Override // javolution.xml.sax.ContentHandler
        public void startPrefixMapping(CharArray charArray, CharArray charArray2) throws SAXException {
            this._sax2Handler.startPrefixMapping(charArray.toString(), charArray2.toString());
        }
    }

    /* loaded from: classes2.dex */
    private static final class Sax2DefaultHandler implements EntityResolver, DTDHandler, org.xml.sax.ContentHandler, ErrorHandler {
        private Sax2DefaultHandler() {
        }

        @Override // org.xml.sax.ContentHandler
        public void characters(char[] cArr, int i, int i2) throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void endDocument() throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void endElement(String str, String str2, String str3) throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void endPrefixMapping(String str) throws SAXException {
        }

        @Override // org.xml.sax.ErrorHandler
        public void error(SAXParseException sAXParseException) throws SAXException {
        }

        @Override // org.xml.sax.ErrorHandler
        public void fatalError(SAXParseException sAXParseException) throws SAXException {
            throw sAXParseException;
        }

        @Override // org.xml.sax.ContentHandler
        public void ignorableWhitespace(char[] cArr, int i, int i2) throws SAXException {
        }

        @Override // org.xml.sax.DTDHandler
        public void notationDecl(String str, String str2, String str3) throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void processingInstruction(String str, String str2) throws SAXException {
        }

        @Override // org.xml.sax.EntityResolver
        public InputSource resolveEntity(String str, String str2) throws SAXException, IOException {
            return null;
        }

        @Override // org.xml.sax.ContentHandler
        public void setDocumentLocator(Locator locator) {
        }

        @Override // org.xml.sax.ContentHandler
        public void skippedEntity(String str) throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void startDocument() throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void startElement(String str, String str2, String str3, org.xml.sax.Attributes attributes) throws SAXException {
        }

        @Override // org.xml.sax.ContentHandler
        public void startPrefixMapping(String str, String str2) throws SAXException {
        }

        @Override // org.xml.sax.DTDHandler
        public void unparsedEntityDecl(String str, String str2, String str3, String str4) throws SAXException {
        }

        @Override // org.xml.sax.ErrorHandler
        public void warning(SAXParseException sAXParseException) throws SAXException {
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static CharSequence toCharSequence(Object obj) {
        return obj instanceof CharSequence ? (CharSequence) obj : Text.valueOf(obj);
    }

    @Override // org.xml.sax.XMLReader
    public org.xml.sax.ContentHandler getContentHandler() {
        if (this._proxy._sax2Handler == DEFAULT_HANDLER) {
            return null;
        }
        return this._proxy._sax2Handler;
    }

    @Override // org.xml.sax.XMLReader
    public DTDHandler getDTDHandler() {
        return this._parser.getDTDHandler();
    }

    @Override // org.xml.sax.XMLReader
    public EntityResolver getEntityResolver() {
        return this._parser.getEntityResolver();
    }

    @Override // org.xml.sax.XMLReader
    public ErrorHandler getErrorHandler() {
        return this._parser.getErrorHandler();
    }

    @Override // org.xml.sax.XMLReader
    public boolean getFeature(String str) throws SAXNotRecognizedException, SAXNotSupportedException {
        return this._parser.getFeature(str);
    }

    @Override // org.xml.sax.XMLReader
    public Object getProperty(String str) throws SAXNotRecognizedException, SAXNotSupportedException {
        return this._parser.getProperty(str);
    }

    @Override // org.xml.sax.XMLReader
    public void parse(String str) throws IOException, SAXException {
        try {
            this._parser.parse(str);
        } finally {
            this._parser.reset();
        }
    }

    @Override // org.xml.sax.XMLReader
    public void parse(InputSource inputSource) throws IOException, SAXException {
        try {
            this._parser.parse(inputSource);
        } finally {
            this._parser.reset();
        }
    }

    @Override // javolution.lang.Reusable
    public void reset() {
        this._parser.reset();
    }

    @Override // org.xml.sax.XMLReader
    public void setContentHandler(org.xml.sax.ContentHandler contentHandler) {
        if (contentHandler == null) {
            throw new NullPointerException();
        }
        this._proxy._sax2Handler = contentHandler;
        this._parser.setContentHandler(this._proxy);
    }

    @Override // org.xml.sax.XMLReader
    public void setDTDHandler(DTDHandler dTDHandler) {
        this._parser.setDTDHandler(dTDHandler);
    }

    @Override // org.xml.sax.XMLReader
    public void setEntityResolver(EntityResolver entityResolver) {
        this._parser.setEntityResolver(entityResolver);
    }

    @Override // org.xml.sax.XMLReader
    public void setErrorHandler(ErrorHandler errorHandler) {
        this._parser.setErrorHandler(errorHandler);
    }

    @Override // org.xml.sax.XMLReader
    public void setFeature(String str, boolean z) throws SAXNotRecognizedException, SAXNotSupportedException {
        this._parser.setFeature(str, z);
    }

    @Override // org.xml.sax.XMLReader
    public void setProperty(String str, Object obj) throws SAXNotRecognizedException, SAXNotSupportedException {
        this._parser.setProperty(str, obj);
    }
}
